//==============================================================================
//
//  File        : sensor_MT9T002.c
//  Description : Firmware Sensor Control File
//  Author      : Philip Lin
//  Revision    : 1.0
//
//=============================================================================

#include "includes_fw.h"
#if defined(DSC_MP3_P_FW)||defined(VIDEO_AMR_R_FW)||defined(VIDEO_AAC_R_FW)||(SENSOR_EN)
#include "config_fw.h"
 
#define TEST_1152_648_MODE          (0)  // test only for MT9T002 3M sensor
#define CROP_1080P_FROM_2304_1296   (0)  // test only for MT9T002 3M sensor
#define ENABLE_ROW_BINNING_2304_648   (0)  // test only for MT9T002 3M sensor

#if BIND_SENSOR_MT9T002

#include "lib_retina.h"
#include "reg_retina.h"

#include "mmp_reg_vif.h"
#include "mmp_reg_scaler.h"
#include "mmp_reg_gpio.h"
#include "mmp_reg_rawproc.h"

#include "mmpf_sensor.h"
#include "mmpf_hif.h"
#include "mmpf_i2cm.h"
#include "mmpf_vif.h"
#include "isp_if.h"

#include "mmp_reg_i2cm.h"
#include "mmps_3gprecd.h"

#include "hdm_ctl.h"

extern MMP_USHORT  gsSensorPreviewWidth[], gsSensorPreviewHeight[]
extern MMP_USHORT  gsCurPreviewMode, gsCurPhaseCount;
extern MMP_USHORT  gsSensorMode;
extern MMP_USHORT  m_usVideoQuality;
extern MMP_USHORT	m_gsISPCoreID;

extern MMPS_3GPRECD_VIDEO_FORMAT m_VideoFmt;
extern MMP_BOOL    gbAutoFocus;

extern MMP_USHORT m_usResolType;

#if (IQ_TABLE_LOAD_FROM_FLASH == 0)
const ISP_UINT8 Sensor_IQ_CompressedText[] = {
#if(CHIP == P_V2)
#include "isp_842_iq_data_v1_MT9T002_LGT.xls.qlz.txt"
#endif
#if (CHIP == VSN_V2)
#endif
};
#endif

//#define SUPPORT_AUTO_FOCUS 0

//#include "sensor_ctl.h"
//#include "preview_ctl.h"
//#include "XDATAmap.h"
//#include "3A_ctl.h"
//#include "MT9T002.h"
//#include "motor_ctl.h"
//------------------------------------------------------------------------------
//  Function    : MT9T002_Sensor_PreviewMode
//  Description :
//------------------------------------------------------------------------------
static void MT9T002_Sensor_SetResolution(ISP_SENSOR_RESOL resol)	// Patrick add
{
	ISP_IF_SNR_SetResolution(resol);

	{
		AITPS_VIF  pVIF = AITC_BASE_VIF;
		volatile MMP_BYTE* pISP = (volatile MMP_BYTE*)AITC_BASE_ISP;
		pVIF->VIF_GRAB_PIXL_ST = gIspIfSnrResolInfo.VIFGrab_H_Start ;
		pVIF->VIF_GRAB_PIXL_ED = gIspIfSnrResolInfo.VIFGrab_H_Start + gIspIfSnrResolInfo.VIFGrab_H_Length -1;//gSensorConfig.VIFGrab_H_Length - 1;
		pVIF->VIF_GRAB_LINE_ST = gIspIfSnrResolInfo.VIFGrab_V_Start ;
		pVIF->VIF_GRAB_LINE_ED = gIspIfSnrResolInfo.VIFGrab_V_Start + gIspIfSnrResolInfo.VIFGrab_V_Length -1;//gSensorConfig.VIFGrab_V_Length - 1;
		pVIF->VIF_INT_LINE = gIspIfSnrResolInfo.VIFGrab_V_Length - 61;// 61;//121;

		if (m_gsISPCoreID == 868) {
			// ISP pipeline selection
			//APICAL_XBYTE[APICAL_CTL_REG1] &= ~(0x80); // clear auto size
			pISP[0x0B] = 0x30;
			pISP[0x09] = 0x0C;

			// IP ColorID setting
			//pISP[0x09] &= ~(0xF0);
			//pISP[0x09] |= (ISP_IF_SNR_GetColorID() == 0 ? 3 : (ISP_IF_SNR_GetColorID() == 1 ? 2 : (ISP_IF_SNR_GetColorID() == 2 ? 1: 0))) * (0x50);
		}
	}
}
//------------------------------------------------------------------------------
//  Function    : MT9T002_Sensor_PreviewMode
//  Description :
//------------------------------------------------------------------------------

static void MT9T002_Sensor_PreviewMode(MMP_USHORT usPreviewmode)
{
	gsCurPreviewMode = usPreviewmode;
	//gsCurPhaseCount = usPhasecount;

	switch (usPreviewmode) {
	case 0:
		RTNA_DBG_Str(3, "Sensor 5M (1920x1080) preview mode\r\n");
		ISP_IF_3A_Control(ISP_3A_DISABLE); //patrick@100518

		ISP_IF_IQ_SetColorTransform(0);//julian@091111
		ISP_IF_SNR_SetBeforeCapture();
		MT9T002_Sensor_SetResolution(ISP_SENSOR_RESOL_1920x1080);

		ISP_IF_3A_Control(ISP_3A_ENABLE); //patrick@100518
		break;

	case 1:
		RTNA_DBG_Str(3, "Sensor preview (1920x1080) mode\r\n");
		switch (gsSensorMode) {
		#if defined(VIDEO_AMR_R_FW)||defined(VIDEO_AAC_R_FW)||(VIDEO_R_EN)
		case SENSOR_VIDEO_MODE:
			RTNA_DBG_Str(3, "SENSOR_VIDEO_MODE\r\n");
			ISP_IF_3A_Control(ISP_3A_DISABLE); //patrick@100518

//				ISP_IF_IQ_SetColorTransform(1);//julian@091111

			if  (m_VideoFmt == MMPS_3GPRECD_VIDEO_FORMAT_MJPEG) //HB
				ISP_IF_IQ_SetColorTransform(0);//julian@091111
			else
				ISP_IF_IQ_SetColorTransform(1);  // for YUV422/MJPEG mode, tomy@2010_04_30

			ISP_IF_SNR_SetBeforePreview();

#if (TEST_1152_648_MODE == 1)			
			MT9T002_Sensor_SetResolution(ISP_SENSOR_RESOL_800x600);
#elif ENABLE_ROW_BINNING_2304_648
			MT9T002_Sensor_SetResolution(ISP_SENSOR_RESOL_800x600);
#else
			MT9T002_Sensor_SetResolution(ISP_SENSOR_RESOL_1920x1080);
#endif			

#if 1
			if (m_VideoFmt == MMPS_3GPRECD_VIDEO_FORMAT_H264){
                if(m_usResolType == VIDRECD_RESOL_1920x1088){  // 1080p
                    VR_AE_SetSensorVsync(gIspIfSnrResolInfo.SensorVsync*30/FULLHD_VIDEO_ENCODE_MAX_FRAME_RATE, gIspIfSnrResolInfo.TargetFPS);        
                }
                else{
                    VR_AE_SetSensorVsync(gIspIfSnrResolInfo.SensorVsync, gIspIfSnrResolInfo.TargetFPS);        
                }
            }
#endif  

			//ISP_IF_AE_SetFPS(0);
			ISP_IF_AE_SetFPS(30);

			//ISP_IF_AE_SetFPS(30);
			ISP_IF_3A_Control(ISP_3A_ENABLE);
			break;
		#endif
		#if defined(DSC_MP3_P_FW)||(DSC_R_EN)
		case SENSOR_DSC_MODE:
			RTNA_DBG_Str(3, "Dsc preview mode\r\n");
			ISP_IF_3A_Control(ISP_3A_DISABLE); //patrick@100518

			ISP_IF_IQ_SetColorTransform(0);//julian@091111
			ISP_IF_SNR_SetBeforePreview();
			MT9T002_Sensor_SetResolution(ISP_SENSOR_RESOL_1280x960);     //Ted 720p 60fps
			//MT9T002_Sensor_SetResolution(ISP_SENSOR_RESOL_1920x1080);
			ISP_IF_3A_Control(ISP_3A_ENABLE);
			break;
		#endif
		}
		break;
	}
}

//------------------------------------------------------------------------------
//  Function    : MMPF_Sensor_Initialize
//  Description :
//------------------------------------------------------------------------------
static MMP_ERR  MMPF_Sensor_Initialize_MT9T002(void)
{
//  MMP_USHORT usData;
	AITPS_GPIO  pGPIO = AITC_BASE_GPIO;
	AITPS_PAD   pPAD  = AITC_BASE_PAD;
	AITPS_VIF  pVIF = AITC_BASE_VIF;

	RTNA_DBG_Str(0, "MMPF_Sensor_Initialize_MT9T002...Begin\r\n");
#if 1
	//RTNA_DBG_Str(0, "Config PS_GPIO pin as pull high IO Pad\r\n");
	// config PS_GPIO as pull high
	//pPAD->PAD_PSGPIO = PAD_E8_CURRENT | PAD_PULL_LOW;
	pGPIO->GPIO_EN[3] |= (1 << 16); // config as output mode
	pGPIO->GPIO_DATA[3] |= (1 << 16);  // Turn On Sensor Power
	RTNA_WAIT_MS(50);

	//Init globol variable used by DSC
	gsSensorLCModeWidth     = 2304;
	gsSensorLCModeHeight    = 1296;//800;
	// use 1.3M for preview, check sensor preview setting
#if (TEST_1152_648_MODE == 1)			
	gsSensorMCModeWidth     = 1152;
	gsSensorMCModeHeight    = 648;//800;
#elif ENABLE_ROW_BINNING_2304_648
	gsSensorMCModeWidth     = 2304;
	gsSensorMCModeHeight    = 648;//800;
#else
    #if CROP_1080P_FROM_2304_1296    
    gsSensorMCModeWidth     = 1920;
    gsSensorMCModeHeight    = 1080;
    #else
	gsSensorMCModeWidth     = 2304;
	gsSensorMCModeHeight    = 1296;//800;
    #endif
#endif

	pPAD->PAD_PSCK = PAD_E8_CURRENT | PAD_E4_CURRENT | PAD_PULL_HIGH;
	pPAD->PAD_PSDA = PAD_E4_CURRENT | PAD_PULL_HIGH;
	pPAD->PAD_PSEN = PAD_E4_CURRENT | PAD_PULL_HIGH;


	MMPF_VIF_SetPIODir(VIF_SIF_SEN, MMP_TRUE);

	#if 1 //PhilipTest@090313
	MMPF_VIF_SetPIOOutput(VIF_SIF_SEN, MMP_TRUE);  //Pin output high
	//RTNA_WAIT_US((15+125)*10); // 15 us + 6 EXT_CLK (48MHz) = 15 us + 125 ns
	RTNA_WAIT_MS(1);
	#endif

	MMPF_VIF_SetPIOOutput(VIF_SIF_SEN, MMP_FALSE);//Pin output low
	//RTNA_WAIT_US(15+125); // 15 us + 6 EXT_CLK (48MHz) = 15 us + 125 ns
	//RTNA_WAIT_US((15+125)*10); // 15 us + 6 EXT_CLK (48MHz) = 15 us + 125 ns
	RTNA_WAIT_MS(1);
    MMPF_VIF_SetPIOOutput(VIF_SIF_SEN, MMP_TRUE);  //Pin output high
    RTNA_WAIT_MS(1);

	pVIF->VIF_SENSR_CLK_CTL  = VIF_SENSR_CLK_EN;

	/********************************************/
	/*Use GPIO to reset sensor for ev board  */
	/*Caution : It's customer dependent !!!     */
	/********************************************/
	/*Reset Sensor 500mS*/

#endif

	/*Reset Sensor 500mS*/
	#if (CHIP == P_V2) || (CHIP == VSN_V2)
	MMPF_VIF_SetPIODir(VIF_SIF_RST, MMP_TRUE);

	MMPF_VIF_SetPIOOutput(VIF_SIF_RST, MMP_FALSE);
	RTNA_WAIT_MS(5/*50*/);

	MMPF_VIF_SetPIOOutput(VIF_SIF_RST, MMP_TRUE);
	RTNA_WAIT_MS(5/*10*/);
	#endif

	ISP_IF_SNR_Init();
	//RTNA_WAIT_MS(120);

	ISP_IF_MOTOR_Init();

	RTNA_DBG_Str(3, "MMPF_Sensor_Initialize_MT9T002...End\r\n");
	return  MMP_ERR_NONE;
}

//------------------------------------------------------------------------------
//  Function    : MMPF_Sensor_PowerDown_MT9T002
//  Description :
//------------------------------------------------------------------------------

static MMP_ERR  MMPF_Sensor_PowerDown_MT9T002(void)
{
	AITPS_VIF  pVIF = AITC_BASE_VIF;
	AITPS_GPIO  pGPIO = AITC_BASE_GPIO;
	AITPS_MIPI pMIPI = AITC_BASE_MIPI;

	pMIPI->MIPI_DATA1_CFG &= ~(MIPI_CSI2_EN);
	pMIPI->MIPI_DATA2_CFG &= ~(MIPI_CSI2_EN);
	MMPF_VIF_EnableInputInterface(MMP_FALSE);

#if SUPPORT_AUTO_FOCUS
    GPIO_OutputControl(AF_EN, FALSE);
#endif


#if (CHIP == P_V2) || (CHIP == VSN_V2)
	//MMPF_VIF_SetPIODir(VIF_SIF_RST, MMP_TRUE);
	//MMPF_VIF_SetPIOOutput(VIF_SIF_RST, MMP_TRUE);  //Pin output high
	//RTNA_WAIT_MS(50);
	//MMPF_VIF_SetPIOOutput(VIF_SIF_RST, MMP_FALSE);//Pin output low
	RTNA_WAIT_MS(20);
#endif

#if 1
	MMPF_VIF_SetPIODir(VIF_SIF_SEN, MMP_TRUE);
	MMPF_VIF_SetPIOOutput(VIF_SIF_SEN, MMP_TRUE);  //Pin output high
    RTNA_WAIT_MS(40);
    MMPF_VIF_SetPIOOutput(VIF_SIF_SEN, MMP_FALSE);//Pin output low
	RTNA_WAIT_MS(20);
#endif

	pVIF->VIF_SENSR_CLK_CTL &= (~ VIF_SENSR_CLK_EN) ;   //output sensor main clock


#if 1
	//RTNA_DBG_Str(3, "Config PS_GPIO pin as LOW\r\n");
	pGPIO->GPIO_DATA[3] &= ~(1 << 16);  // Turn Off Sensor Power
#endif
	RTNA_WAIT_MS(20);

	RTNA_DBG_Str3( "MMPF_Sensor_PowerDown_MT9T002() \r\n");
	return  MMP_ERR_NONE;
}

//------------------------------------------------------------------------------
//  Function    : MMPF_Sensor_SetFrameRate_MT9T002
//  Description :
//------------------------------------------------------------------------------
static MMP_ERR  MMPF_Sensor_SetFrameRate_MT9T002(MMP_UBYTE ubFrameRate)
{
	return  MMP_ERR_NONE;
}

//------------------------------------------------------------------------------
//  Function    : MMPF_Sensor_SetPreviewMode
//  Description :
//------------------------------------------------------------------------------

static MMP_ERR MMPF_Sensor_SetPreviewMode_MT9T002(MMP_USHORT usPreviewmode)
{
	MT9T002_Sensor_PreviewMode(usPreviewmode);

	return  MMP_ERR_NONE;
}

//------------------------------------------------------------------------------
//  Function    : MMPF_Sensor_SetPreviewMode
//  Description :
//------------------------------------------------------------------------------

static MMP_ERR MMPF_Sensor_ChangePreviewMode_MT9T002(
						MMP_USHORT usCurPreviewmode, MMP_USHORT usCurPhasecount,
						MMP_USHORT usNewPreviewmode, MMP_USHORT usNewPhasecount)
{
	MT9T002_Sensor_PreviewMode(usNewPreviewmode);

	return  MMP_ERR_NONE;
}

//------------------------------------------------------------------------------
//  Function    : MMPF_Sensor_ChangeMode
//  Description :
//------------------------------------------------------------------------------

/*static*/ MMP_ERR MMPF_Sensor_ChangeMode_MT9T002(MMP_USHORT usPreviewmode, MMP_USHORT usCapturemode)
{
	switch (usPreviewmode) {
	case 0:
		switch (usCapturemode) {
		case 0:
			break;
		case 1:
			break;
		}
		break;
	case 1:
		switch (usCapturemode) {
		case 0:// SXGA preview, 5M capture
			MMPF_Sensor_SetPreviewMode_MT9T002(0);
			// wait 3 frame ...
		   // MMPF_Sensor_WaitFrame(5);
			break;
		case 1:
			MMPF_Sensor_SetPreviewMode_MT9T002(1);
			// wait 3 frame ...
			//MMPF_Sensor_WaitFrame(3);

			break;
		}
		break;
	}

	return  MMP_ERR_NONE;
}

//------------------------------------------------------------------------------
//  Function    : MMPF_Sensor_InitializeVIF
//  Description :
//------------------------------------------------------------------------------
static MMP_ERR  MMPF_Sensor_InitializeVIF_MT9T002(void)
{
	AITPS_MIPI  pMIPI = AITC_BASE_MIPI;
	AITPS_VIF  pVIF = AITC_BASE_VIF;
	RTNA_DBG_Str(0, "ISP_IF_SNR_Register...S\r\n");

	// register sensor (functions and variables)
	ISP_IF_SNR_Register();

	RTNA_DBG_Str(0, "ISP_IF_SNR_Register...E\r\n");

	if (ISP_IF_VER_GetIspLibVer().MajorVer != ISP_IF_VER_GetIQFormatVer().MajorVer ||  \
		ISP_IF_VER_GetIspLibVer().MinorVer != ISP_IF_VER_GetIQFormatVer().MinorVer )
	{
		RTNA_DBG_Str(0, "Error: A version mismatch was encountered.\r\n");
	}
	
#if SUPPORT_AUTO_FOCUS
    GPIO_OutputControl(AF_EN, TRUE);
	RTNA_WAIT_MS(20);
#endif

	// register motor
	ISP_IF_MOTOR_Register();

	RTNA_DBG_Str(0, "ISP_IF_3A_Register...S\r\n");
	// register 3A
	ISP_IF_3A_Register();
	RTNA_DBG_Str(0, "ISP_IF_3A_Register...E\r\n");

	RTNA_DBG_Str(0, "ISP_IF_3A_Init...S\r\n");
	// initialize 3A
	ISP_IF_3A_Init();
	RTNA_DBG_Str(0, "ISP_IF_3A_Init...E\r\n");

//	pMIPI->MIPI_DATA1_DEL = 0x40; // From KW
//	pMIPI->MIPI_DATA2_DEL = 0x40; // From KW
//	pMIPI->MIPI_DATA3_DEL = 0x40; // From KW
//	pMIPI->MIPI_DATA4_DEL = 0x40; // From KW

	pMIPI->MIPI_DATA1_SOT = 0x10; // From KW
	pMIPI->MIPI_DATA2_SOT = 0x10; // From KW
	pMIPI->MIPI_DATA3_SOT = 0x10; // From KW
	pMIPI->MIPI_DATA4_SOT = 0x10; // From KW
	
	//MMPF_VIF_RegisterInputInterface(MMPF_VIF_PARALLEL);
	//pVIF->VIF_SENSR_CTL      = VIF_SENSR_LATCH_NEG | VIF_HSYNC_POLAR | VIF_12BPP_OUT_EN;
	MMPF_VIF_RegisterInputInterface(MMPF_VIF_MIPI);


	
	return  MMP_ERR_NONE;
}

//------------------------------------------------------------------------------
//  Function    : MMPF_Sensor_InitializeISP
//  Description :
//------------------------------------------------------------------------------
static MMP_ERR  MMPF_Sensor_InitializeISP_MT9T002(void)
{
	return  MMP_ERR_NONE;
}

//============================================================================

//------------------------------------------------------------------------------
//  Function    : MMPF_Sensor_SetAFPosition_MT9T002
//  Description :
// ---------------------------------------
static MMP_ERR MMPF_Sensor_SetAFPosition_MT9T002(MMP_UBYTE ubPos)
{
#if 1
	//if (gISPConfig.AutoFocusMode == VENUS_AF_MODE_MANUAL) {
		//gAFConfig.AFPos = ubPos;
		ISP_IF_AF_SetPos(ubPos);
	//}
#endif
	return  MMP_ERR_NONE;
}

//------------------------------------------------------------------------------
//  Function    : MMPF_Sensor_Do3AOperation
//  Description :
//------------------------------------------------------------------------------
static MMP_ERR  MMPF_Sensor_DoAWBOperation_MT9T002(void)
{
	ISP_IF_R_GetAWBAcc();

	ISP_IF_R_DoAWB();
	
	//RTNA_DBG_Str(0, "Do3AOperation_MT9T002()\r\n");

	return  MMP_ERR_NONE;
}

//------------------------------------------------------------------------------
//  Function    : MMPF_Sensor_DoAEOperation_ST
//  Description :
//------------------------------------------------------------------------------
static MMP_ERR  MMPF_Sensor_DoAEOperation_ST_MT9T002(void)
{
	//ISP_IF_R_DoAE();
	//RTNA_DBG_Str(0, "DoAEOperation_MT9T002()\r\n");
	static ISP_UINT32 frame_cnt = 0;
	static ISP_UINT32 again, dgain;

	switch (frame_cnt++ % 6) {
	case 0:
		ISP_IF_AE_Execute();

		again = ISP_IF_AE_GetAGain();
		dgain = ISP_IF_AE_GetDGain();
		// end of special conversion ==============================================================

		gsSensorFunction->MMPF_Sensor_SetSensorShutter(ISP_IF_AE_GetShutter(), ISP_IF_AE_GetVsync());
		gsSensorFunction->MMPF_Sensor_SetSensorGain(again);
		break;

	}

	return  MMP_ERR_NONE;
}

//------------------------------------------------------------------------------
//  Function    : MMPF_Sensor_DoAEOperation_END
//  Description :
//------------------------------------------------------------------------------
static MMP_ERR  MMPF_Sensor_DoAEOperation_END_MT9T002(void)
{
	//ISP_IF_R_DoAE();
	//RTNA_DBG_Str(0, "DoAEOperation_MT9T002()\r\n");
	static ISP_UINT32 frame_cnt = 0;
	
	ISP_IF_R_GetAEAcc();

	switch (frame_cnt++ % 6) {
	case 1:
		ISP_IF_SNR_SetDGain(ISP_IF_AE_GetDGain());
		ISP_IF_SNR_SetAddMode(ISP_IF_AE_GetAdditionMode());
		break;
	}

	return  MMP_ERR_NONE;
}

//------------------------------------------------------------------------------
//  Function    : MMPF_Sensor_DoAFOperation
//  Description :
//------------------------------------------------------------------------------
static MMP_ERR  MMPF_Sensor_DoAFOperation_MT9T002(void)
{
#if SUPPORT_AUTO_FOCUS
	if(gbAutoFocus == MMP_TRUE){
		//VR_AF_GetAcc();
		ISP_IF_R_GetAFAcc();
		ISP_IF_R_DoAF();
	}
#endif

	//RTNA_DBG_Str(0, "Do3AOperation_MT9T002()\r\n");
	
	return  MMP_ERR_NONE;
}

//------------------------------------------------------------------------------
//  Function    : MMPF_Sensor_DoIQOperation_MT9T002
//  Description :
//------------------------------------------------------------------------------
static MMP_ERR  MMPF_Sensor_DoIQOperation_MT9T002(void)
{
	// set IQ at frame end to ensure frame sync
	ISP_IF_R_DoIQ();

	//RTNA_DBG_Str(0, "DoIQOperation_MT9T002()\r\n");
	
	return  MMP_ERR_NONE;
}

// Steven ADD
//------------------------------------------------------------------------------
//  Function    : MMPF_SetLightFreq
//  Description :
//------------------------------------------------------------------------------
static MMP_ERR  MMPF_SetLightFreq_MT9T002(MMP_USHORT usMode)
{
	RTNA_DBG_Str(0, "MMPF_SetLightFreq_IMX045ES : ");
	RTNA_DBG_Short(0, usMode);
	RTNA_DBG_Str(0, "\r\n");

	/*
	typedef enum {
		VENUS_FLICKER_MODE_OFF              = 0,
		VENUS_FLICKER_MODE_AUTO             = 1,
		VENUS_FLICKER_MODE_60HZ             = 2,
		VENUS_FLICKER_MODE_50HZ             = 3,
		VENUS_FLICKER_MODE_CAL_BASESHUTTER  = 4
	} VENUS_FLICKER_MODE;
	*/

	switch(usMode) {
	case 0:
	case 2:
		//gISPConfig.FlickerMode = VENUS_FLICKER_MODE_60HZ;
		ISP_IF_AE_SetFlicker(ISP_AE_FLICKER_60HZ);
		break;
	case 1:
	case 3:
		//gISPConfig.FlickerMode = VENUS_FLICKER_MODE_50HZ;
		ISP_IF_AE_SetFlicker(ISP_AE_FLICKER_50HZ);
		break;
	default:
		//gISPConfig.FlickerMode = VENUS_FLICKER_MODE_AUTO;
		ISP_IF_AE_SetFlicker(ISP_AE_FLICKER_AUTO);
	}

	return  MMP_ERR_NONE;
}

static MMP_ERR  MMPF_SetStableState_MT9T002(MMP_BOOL bStableState)
{
	return  MMP_ERR_NONE;
}

MMP_ERR MMPF_SetHistEQState_MT9T002(MMP_BOOL bHistEQState)
{

	return  MMP_ERR_NONE;
}

static MMP_ERR  MMPF_Sensor_SetReg_MT9T002(MMP_USHORT usAddr, MMP_USHORT usData)
{
	//MMPF_I2cm_WriteReg(usAddr, usData);
	 MMPF_Sensor_WriteI2C(usAddr,usData);
	return  MMP_ERR_NONE;
}

static MMP_ERR  MMPF_Sensor_GetReg_MT9T002(MMP_USHORT usAddr, MMP_USHORT *usData)
{
	//MMPF_I2cm_ReadReg(usAddr, usData);
	*usData = MMPF_Sensor_ReadI2C(usAddr) ;
	return  MMP_ERR_NONE;
}


static MMP_ERR  MMPF_Sensor_SetImageScene_MT9T002(MMP_USHORT imgSceneID)
{
/*
typedef enum {
	ISP_SCENE_AUTO					= 0,	// scene mode
	ISP_SCENE_PORTRAIT				= 1,	// scene mode
	ISP_SCENE_LANDSCAPE				= 2,	// scene mode
	ISP_SCENE_SPORTS				= 3,	// scene mode
	ISP_SCENE_SUNSET				= 4,	// scene mode
	ISP_SCENE_DUSK					= 5,	// scene mode
	ISP_SCENE_DAWN					= 6,	// scene mode
	ISP_SCENE_NIGHT_SHOT			= 7,	// scene mode
	ISP_SCENE_AGAINST_LIGHT			= 8,	// scene mode
	ISP_SCENE_TEXT					= 9,	// scene mode
	ISP_SCENE_MANUAL				= 10,	// scene mode
	ISP_SCENE_INDOOR				= 11,	// scene mode
	ISP_SCENE_SNOW					= 12,	// scene mode
	ISP_SCENE_FALL					= 13,	// scene mode
	ISP_SCENE_WAVE					= 14,	// scene mode
	ISP_SCENE_FIREWORKS				= 15,	// scene mode
	ISP_SCENE_SHOW_WIN				= 16,	// scene mode
	ISP_SCENE_CANDLE				= 17,	// scene mode
	ISP_SCENE_NONE					= 18	// camera mode
} ISP_SCENE;
*/
	imgSceneID = (imgSceneID % (ISP_SCENE_NONE+1));

	RTNA_DBG_Str(3, "MMPF_SetImageScene_MT9T002 : ");
	RTNA_DBG_Byte(3, imgSceneID);
	RTNA_DBG_Str(3, "\r\n");

	//if (g3AConfig.Control3A == ISP_3A_ENABLE)
		MMPF_Sensor_CheckFrameEnd(1);
	ISP_IF_F_SetScene(imgSceneID);

	return  MMP_ERR_NONE;
}

static MMP_ERR  MMPF_Sensor_SetAEMode_MT9T002(MMP_UBYTE ubAEMode, MMP_UBYTE ubISOMode)
{
/*
typedef enum {
	AE_MODE_AUTO						= 0,
	AE_MODE_MANUAL						= 1,
	AE_MODE_ISO							= 2,
	AE_MODE_SHUTTER						= 3
} VENUS_AE_MODE;
*/
/*
typedef enum {
	AE_ISO_AUTO					= 0,
	AE_ISO_50					= 1,
	AE_ISO_100					= 2,
	AE_ISO_200					= 3,
	AE_ISO_400					= 4,
	AE_ISO_800					= 5,
	AE_ISO_1600					= 6,
	AE_ISO_3200					= 7,
	ISP_AE_ISO_NUM
} VENUS_AE_ISO;
*/
	RTNA_DBG_Str(3, "MMPF_Sensor_SetAEMode_MT9T002 : ");
	RTNA_DBG_Byte(3, ubAEMode);
	RTNA_DBG_Str(3, ": ");
	RTNA_DBG_Byte(3, ubISOMode);
	RTNA_DBG_Str(3, "\r\n");

	//if (g3AConfig.Control3A == ISP_3A_ENABLE)
	//MMPF_Sensor_CheckFrameEnd(1);
	//Venus_SetAEMode(ubAEMode, ubISOMode);
	if (ubAEMode == 3)
		ISP_IF_AE_SetISO(ISP_AE_ISO_AUTO);
	else
		ISP_IF_AE_SetISO(ubISOMode);
	
	return  MMP_ERR_NONE;
}

static MMP_ERR  MMPF_Sensor_SetAFMode_MT9T002(MMP_UBYTE ubAFMode)
{
/*
typedef enum {
	VENUS_AF_MODE_AUTO					= 0,
	VENUS_AF_MODE_MANUAL				= 1,
	VENUS_AF_MODE_MACRO					= 2,
	VENUS_AF_MODE_FULL					= 3,
	VENUS_AF_MODE_MOTOR_TEST            = 4,
	VENUS_AF_MODE_NULL					= 5
} VENUS_AF_MODE;
*/
	RTNA_DBG_Str(3, "MMPF_Sensor_SetAFMode_MT9T002 : ");
	RTNA_DBG_Byte(3, ubAFMode);
	RTNA_DBG_Str(3, "\r\n");

	//gISPConfig.AutoFocusMode = (MMP_UBYTE)ubAFMode;
	//if (g3AConfig.Control3A == ISP_3A_ENABLE)
	//	MMPF_Sensor_CheckFrameEnd(1);
	ISP_IF_AF_SetMode(ubAFMode);
	return  MMP_ERR_NONE;
}

//======================================================================//
// function : MMPF_Sensor_SetImageEffect                                //
// parameters:                                                          //
// return :                                                             //
// description :                                                        //
//======================================================================//
static MMP_ERR  MMPF_Sensor_SetImageEffect_MT9T002(MMP_USHORT imgEffectID)
{
/*
typedef enum {
	ISP_IMAGE_EFFECT_NORMAL			= 0,
	ISP_IMAGE_EFFECT_GREY			= 1,
	ISP_IMAGE_EFFECT_SEPIA			= 2,
	ISP_IMAGE_EFFECT_NEGATIVE		= 3,
	ISP_IMAGE_EFFECT_ANTIQUE		= 4,
	ISP_IMAGE_EFFECT_WATERCOLOR		= 5,
	ISP_IMAGE_EFFECT_PORTRAIT		= 6,
	ISP_IMAGE_EFFECT_LANDSCAPE		= 7,
	ISP_IMAGE_EFFECT_SUNSET			= 8,
	ISP_IMAGE_EFFECT_DUSK			= 9,
	ISP_IMAGE_EFFECT_DAWN			= 10,
	ISP_IMAGE_EFFECT_RED			= 11,
	ISP_IMAGE_EFFECT_GREEN			= 12,
	ISP_IMAGE_EFFECT_BLUE			= 13,
	ISP_IMAGE_EFFECT_YELLOW			= 15,
	ISP_IMAGE_EFFECT_EMBOSS			= 17,
	ISP_IMAGE_EFFECT_OIL			= 18,
	ISP_IMAGE_EFFECT_BW				= 19,
	ISP_IMAGE_EFFECT_SKETCH			= 20,
	ISP_IMAGE_EFFECT_CRAYONE		= 21,
	ISP_IMAGE_EFFECT_WHITEBOARD		= 22,
	ISP_IMAGE_EFFECT_BLACKBOARD		= 23,
	ISP_IMAGE_EFFECT_VIVID			= 24,
	ISP_IMAGE_EFFECT_NUM
} ISP_IMAGE_EFFECT;
*/

	imgEffectID = (imgEffectID % (ISP_IMAGE_EFFECT_NUM+1));

	RTNA_DBG_Str(3, "MMPF_Sensor_SetImageEffect_MT9T002 : ");
	RTNA_DBG_Byte(3, imgEffectID);
	RTNA_DBG_Str(3, "\r\n");

	//gISPConfig.ImageEffect = (MMP_USHORT)imgEffectID;
	//if (g3AConfig.Control3A == ISP_3A_ENABLE)
	//	MMPF_Sensor_CheckFrameEnd(1);
	ISP_IF_F_SetImageEffect(imgEffectID);

	return  MMP_ERR_NONE;
}

static MMP_ERR  MMPF_Sensor_SetAWBType_MT9T002(MMP_UBYTE ubType)
{
#if 0
	RTNA_DBG_Str(3, "MMPF_Sensor_SetAWBType_MT9T002 : ");
	RTNA_DBG_Byte(3, ubType);
	RTNA_DBG_Str(3, "\r\n");

	cAWBtype = ubType;
#endif
	return  MMP_ERR_NONE;
}
static MMP_ERR  MMPF_Sensor_SetContrast_MT9T002(MMP_UBYTE ubLevel)
{
	RTNA_DBG_Str(3, "MMPF_Sensor_Contrast_MT9T002 : ");
	RTNA_DBG_Byte(3, ubLevel);
	RTNA_DBG_Str(3, "\r\n");

	//gISPConfig.ContrastLevel = ubLevel;
	ISP_IF_F_SetContrast(ubLevel);

	return  MMP_ERR_NONE;
}
static MMP_ERR  MMPF_Sensor_SetSaturation_MT9T002(MMP_UBYTE ubLevel)
{
	RTNA_DBG_Str(3, "MMPF_Sensor_SetSaturation_MT9T002 : ");
	RTNA_DBG_Byte(3, ubLevel);
	RTNA_DBG_Str(3, "\r\n");

	//gISPConfig.SaturationLevel = ubLevel;
	ISP_IF_F_SetSaturation(ubLevel);

	return  MMP_ERR_NONE;
}
static MMP_ERR  MMPF_Sensor_SetSharpness_MT9T002(MMP_UBYTE ubLevel)
{
	RTNA_DBG_Str(3, "MMPF_Sensor_SetSharpness_MT9T002 : ");
	RTNA_DBG_Byte(3, ubLevel);
	RTNA_DBG_Str(3, "\r\n");

	//gISPConfig.SharpnessLevel = ubLevel;
	ISP_IF_F_SetSharpness(ubLevel);

	return  MMP_ERR_NONE;
}

static MMP_ERR  MMPF_Sensor_SetHue_MT9T002(MMP_SHORT ubLevel)
{
	RTNA_DBG_Str(3, "MMPF_Sensor_SetHue_MT9T002 : ");
	RTNA_DBG_Byte(3, ubLevel);
	RTNA_DBG_Str(3, "\r\n");

	ISP_IF_F_SetHue(ubLevel);

	return  MMP_ERR_NONE;
}

static MMP_ERR  MMPF_Sensor_SetGamma_MT9T002(MMP_SHORT ubLevel)
{
	RTNA_DBG_Str(3, "MMPF_Sensor_SetGamma_MT9T002 : ");
	RTNA_DBG_Byte(3, ubLevel);
	RTNA_DBG_Str(3, "\r\n");

	ISP_IF_F_SetGamma(ubLevel);

	return  MMP_ERR_NONE;
}

static MMP_ERR  MMPF_Sensor_SetBacklight_MT9T002(MMP_UBYTE ubLevel)
{
	RTNA_DBG_Str(3, "MMPF_Sensor_SetBacklight_MT9T002 : ");
	RTNA_DBG_Byte(3, ubLevel);
	RTNA_DBG_Str(3, "\r\n");

//	ISP_IF_F_SetBacklight(ubLevel);
	if(ubLevel > 1){
		ISP_IF_F_SetWDR(ISP_WDR_DISABLE);
	}
	else{
		ISP_IF_F_SetWDR(ISP_WDR_ENABLE);
	}

	return  MMP_ERR_NONE;
}



static void  MMPF_Sensor_SetCaptureISPSetting_MT9T002(MMP_UBYTE usCaptureBegin)
{
	AITPS_VIF  pVIF = AITC_BASE_VIF;
	MMP_ULONG ulVIF_Width, ulVIF_Height;

	/* ToDo: setting IOS and ISP windows*/
	if(MMP_TRUE == usCaptureBegin){
		ulVIF_Width = (pVIF->VIF_GRAB_PIXL_ED - pVIF->VIF_GRAB_PIXL_ST + 1);
		ulVIF_Height = (pVIF->VIF_GRAB_LINE_ED - pVIF->VIF_GRAB_LINE_ST + 1);
		//gSensorFunc.SetISPWindows(ulVIF_Width,ulVIF_Height);
	}
	
	return;
}

/*Prepare for raw preview zoom*/
static void  MMPF_Sensor_SetISPWindow_MT9T002(MMP_ULONG ulWidth, MMP_ULONG ulHeight)
{
	//gSensorFunc.SetISPWindows(ulWidth,ulHeight);
	return;
}

/*Check AIT can preview in this resolution*/
static MMP_UBYTE  MMPF_Sensor_CheckPreviewAbility_MT9T002(MMP_USHORT usPreviewmode)
{
	switch(usPreviewmode){
		case 0:                 //5M can't preview
			return MMP_TRUE;
			break;
		case 1:                 //1.3M can preview
			return MMP_TRUE;
			break;
	}
	
	return MMP_TRUE;            //5M and 1.3M always can preview
}

static void SetAFWin_MT9T002(MMP_USHORT usIndex, MMP_USHORT usPreviewWidth, MMP_USHORT usPreviewHeight,
					MMP_USHORT  usStartX, MMP_USHORT  usStartY, MMP_USHORT  usWidth, MMP_USHORT  usHeight)
{

	DBG_S3("SetAFWin (TODO)\r\n");
}

//static MMP_BOOL VGAPreview = MMP_TRUE;
static void SetAFEnable_MT9T002(MMP_UBYTE enable)
{
//    if (enable) {
		RTNA_DBG_Str(3, "VENUS_ISP_AUTO_FOCUS_STATUS_START\r\n");
		ISP_IF_AF_Control(ISP_AF_START);
		//actually calling SNR_MT9T002_SetAutoFocusControl()
//    } else {
//        RTNA_DBG_Str(3, "VENUS_ISP_AUTO_FOCUS_STATUS_STOP\r\n");
//        ISP_IF_AF_Control(ISP_AF_STOP);
//    }
}

static MMP_ERR MMPF_Sensor_SetAEEnable_MT9T002(MMP_UBYTE bEnable)
{
	/*
	if (bEnable) {
		g3AConfig.AE_Enabled     = ON;
	}
	else {
		g3AConfig.AE_Enabled     = OFF;
	}*/

	ISP_IF_3A_SetSwitch(ISP_3A_ALGO_AE, bEnable);

	return MMP_ERR_NONE;
}

static MMP_ERR MMPF_Sensor_SetAWBEnable_MT9T002(MMP_UBYTE bEnable)
{
#if 0
	if (bEnable) {
		g3AConfig.AWB_Enabled    = ON;
		g3AConfig.AWBRGB_Enabled = ON;
	}
	else {
		g3AConfig.AWB_Enabled    = OFF;
		g3AConfig.AWBRGB_Enabled = OFF;
	}
#endif


	if(bEnable)
		ISP_IF_AWB_SetMode(ISP_AWB_MODE_AUTO);
	else
		ISP_IF_AWB_SetMode(ISP_AWB_MODE_MANUAL);

	return MMP_ERR_NONE;
}
static void SetAEsmooth_MT9T002(MMP_UBYTE smooth)  {return;}
static MMP_ERR MMPF_Sensor_SetExposureValue_MT9T002(MMP_UBYTE ev)
{
	RTNA_DBG_Str(3, "MMPF_Sensor_SetExposureValue_MT9T002 : ");
	//RTNA_DBG_Byte(3, gISPConfig.EV);
	//RTNA_DBG_Str(3, " : ");
	RTNA_DBG_Byte(3, ev);
	RTNA_DBG_Str(3, "\r\n");

	ISP_IF_AE_SetEV(ev);

	return MMP_ERR_NONE;
}

static MMP_UBYTE GetAFPosition_MT9T002     (void){ return 0;/*volatile MMP_UBYTE *GPIO_BASE_B = (volatile MMP_UBYTE *)0x80009400;  return GPIO_BASE_B[0xB0];*/}


static MMP_UBYTE GetAFEnable_MT9T002(void)
{
	//return 0;
	return ISP_IF_AF_GetResult();
}

static MMP_UBYTE GetExposureValue_MT9T002  (void){return ISP_IF_AE_GetEV();}
static MMP_UBYTE GetAEsmooth_MT9T002       (void){return 0;}
//------------------------------------------------------------------------------
//  Function    : MMPF_Sensor_Set3AStatus
//  Description :
//------------------------------------------------------------------------------
static MMP_ERR	MMPF_Sensor_Set3AStatus_MT9T002(MMP_BOOL bEnable)
{
	#if 0
	MMPF_Sensor_3A_SetInterrupt(bEnable);
	#else
	if (bEnable)
		ISP_IF_3A_Control(ISP_3A_ENABLE);
	else
		ISP_IF_3A_Control(ISP_3A_DISABLE);
	#endif
	return	MMP_ERR_NONE;
}

static void  MMPF_Sensor_SetColorID_MT9T002(MMPF_SENSOR_ROTATE_TYPE RotateType)
{
	switch(RotateType) {
	case MMPF_SENSOR_ROTATE_NO_ROTATE:
		break;
	case MMPF_SENSOR_ROTATE_RIGHT_90:
		break;
	case MMPF_SENSOR_ROTATE_RIGHT_180:
		break;
	case MMPF_SENSOR_ROTATE_RIGHT_270:
		break;
	case MMPF_SENSOR_ROTATE_H_MIRROR:
		break;
	case MMPF_SENSOR_ROTATE_V_FLIP:
		break;
	}

	ISP_IF_IQ_SetDirection((ISP_UINT8)RotateType);
	return;
}

MMPF_SENSOR_FUNCTION  SensorFunction_MT9T002 =
{
	MMPF_Sensor_Initialize_MT9T002,
	MMPF_Sensor_InitializeVIF_MT9T002,
	MMPF_Sensor_InitializeISP_MT9T002,
	MMPF_Sensor_PowerDown_MT9T002,
	MMPF_Sensor_SetFrameRate_MT9T002,
	MMPF_Sensor_ChangeMode_MT9T002,
	MMPF_Sensor_ChangePreviewMode_MT9T002,
	MMPF_Sensor_SetPreviewMode_MT9T002,
	MMPF_Sensor_SetReg_MT9T002,
	MMPF_Sensor_GetReg_MT9T002,
	MMPF_Sensor_DoAWBOperation_MT9T002,
	MMPF_Sensor_DoAEOperation_ST_MT9T002,
	MMPF_Sensor_DoAEOperation_END_MT9T002,
	MMPF_Sensor_DoAFOperation_MT9T002,
	MMPF_Sensor_DoIQOperation_MT9T002,
	MMPF_Sensor_SetImageEffect_MT9T002,
	MMPF_SetLightFreq_MT9T002,
	MMPF_SetStableState_MT9T002,
	MMPF_SetHistEQState_MT9T002,
	MMPF_Sensor_SetAFPosition_MT9T002,
	SetAFWin_MT9T002,
	SetAFEnable_MT9T002,
	MMPF_Sensor_SetAEEnable_MT9T002,
	MMPF_Sensor_SetAWBEnable_MT9T002,
	MMPF_Sensor_SetExposureValue_MT9T002,
	SetAEsmooth_MT9T002,
	MMPF_Sensor_SetImageScene_MT9T002,
	GetAFPosition_MT9T002,
	GetAFEnable_MT9T002,
	GetExposureValue_MT9T002,
	GetAEsmooth_MT9T002,
	MMPF_Sensor_SetAWBType_MT9T002,
	MMPF_Sensor_SetContrast_MT9T002,
	MMPF_Sensor_SetSaturation_MT9T002,
	MMPF_Sensor_SetSharpness_MT9T002,
	MMPF_Sensor_SetHue_MT9T002,
	MMPF_Sensor_SetGamma_MT9T002,
 //   MMPF_Sensor_SetBacklight_MT9T002,
	MMPF_Sensor_SetAEMode_MT9T002,
	MMPF_Sensor_SetAFMode_MT9T002,
	MMPF_Sensor_SetCaptureISPSetting_MT9T002,
	MMPF_Sensor_SetISPWindow_MT9T002,
	MMPF_Sensor_CheckPreviewAbility_MT9T002,
	MMPF_Sensor_Set3AStatus_MT9T002,
	MMPF_Sensor_SetColorID_MT9T002
};


#if (SENSOR_IF == SENSOR_IF_MIPI_1_LANE)
//MIPI 1 Lane
uint16 SNR_MT9T002_Reg_Init_Customer[] = {
	0x31AE, 0x201,
	0x301A,0x0058, //disable streaming
	0xFFFF, 10, //delay 5us
	0x31AE, 0x201, //Output 1-lane MIPI
	//Configure for Serial Interface
	0x301A,0x0058, //Drive Pins,Parallel Enable,SMIA Serializer Disable
	0x3064, 0x1802, 	//Disable Embedded Data
	//Optimized Gain Configuration
	0x3EE0, 0x1500, 	// DAC_LD_20_21
	0x3EEA,0x001D,
	0x31E0,0x1E01,
	0x3F06,0x046A,
	0x3ED2,0x0186,	// upadate 9/30
	0x3ED4,0x8F2C,	// upadate 9/30
	0x3ED6,0x2244,	// upadate 9/30
	0x3ED8,0x6442,	// upadate 9/30
	0x30BA, 0x002C, //Dither enable
	0x3046, 0x4038,		// Enable Flash Pin
	0x3048, 0x8480,		// Flash Pulse Length
	 0x3ED0, 0x0016, 	// DAC_LD_4_5
	 0x3ED0, 0x0036, 	// DAC_LD_4_5
	 0x3ED0, 0x0076, 	// DAC_LD_4_5
	 0x3ED0, 0x00F6, 	// DAC_LD_4_5
	 0x3ECE, 0x1003, 	// DAC_LD_2_3
	 0x3ECE, 0x100F, 	// DAC_LD_2_3
	 0x3ECE, 0x103F, 	// DAC_LD_2_3
	 0x3ECE, 0x10FF, 	// DAC_LD_2_3
	 0x3ED0, 0x00F6, 	// DAC_LD_4_5
	 0x3ED0, 0x04F6, 	// DAC_LD_4_5
	 0x3ED0, 0x24F6, 	// DAC_LD_4_5
	 0x3ED0, 0xE4F6, 	// DAC_LD_4_5
	 0x3EE6, 0xA480, 	// DAC_LD_26_27
	 0x3EE6, 0xA080, 	// DAC_LD_26_27
	 0x3EE6, 0x8080, 	// DAC_LD_26_27
	 0x3EE6, 0x0080, 	// DAC_LD_26_27
	0x3EE6, 0x0080, 	// DAC_LD_26_27
	0x3EE8, 0x2024, 	// DAC_LD_28_29
	0x30FE, 128, //Noise Pedestal of 128

	//Assuming Input Clock of 24MHz.  Output Clock will be 70Mpixel/s
	 0x302A, 0x0005, 	// VT_PIX_CLK_DIV
	 0x302C, 0x0004, 	// VT_SYS_CLK_DIV
	 0x302E, 0x0002, 	// PRE_PLL_CLK_DIV
	 0x3030, 0x0040, 	// PLL_MULTIPLIER
	 0x3036, 0x000A, 	// OP_PIX_CLK_DIV
	 0x3038, 0x0001, 	// OP_SYS_CLK_DIV
	 0x31AC, 0x0A0A, 	// DATA_FORMAT_BITS
	//MIPI TIMING
	0x31B0, 40,                          // FRAME PREAMBLE
	0x31B2, 14,                          // LINE PREAMBLE
	0x31B4, 0x2743,                      // MIPI TIMING 0
	0x31B6, 0x114E,                      // MIPI TIMING 1
	0x31B8, 0x2049,                      // MIPI TIMING 2
	0x31BA, 0x0186,                      // MIPI TIMING 3
	0x31BC, 0x8005,                      // MIPI TIMING 4
	0x31BE, 0x2003,                      // MIPI CONFIG STATUS
	//0x31B0, 41,
	//Sequencer
	0x3088, 0x8000,
	0x3086, 0x4540,
	0x3086, 0x6134,
	0x3086, 0x4A31,
	0x3086, 0x4342,
	0x3086, 0x4560,
	0x3086, 0x2714,
	0x3086, 0x3DFF,
	0x3086, 0x3DFF,
	0x3086, 0x3DEA,
	0x3086, 0x2704,
	0x3086, 0x3D10,
	0x3086, 0x2705,
	0x3086, 0x3D10,
	0x3086, 0x2715,
	0x3086, 0x3527,
	0x3086, 0x053D,
	0x3086, 0x1045,
	0x3086, 0x4027,
	0x3086, 0x0427,
	0x3086, 0x143D,
	0x3086, 0xFF3D,
	0x3086, 0xFF3D,
	0x3086, 0xEA62,
	0x3086, 0x2728,
	0x3086, 0x3627,
	0x3086, 0x083D,
	0x3086, 0x6444,
	0x3086, 0x2C2C,
	0x3086, 0x2C2C,
	0x3086, 0x4B01,
	0x3086, 0x432D,
	0x3086, 0x4643,
	0x3086, 0x1647,
	0x3086, 0x435F,
	0x3086, 0x4F50,
	0x3086, 0x2604,
	0x3086, 0x2684,
	0x3086, 0x2027,
	0x3086, 0xFC53,
	0x3086, 0x0D5C,
	0x3086, 0x0D60,
	0x3086, 0x5754,
	0x3086, 0x1709,
	0x3086, 0x5556,
	0x3086, 0x4917,
	0x3086, 0x145C,
	0x3086, 0x0945,
	0x3086, 0x0017,
	0x3086, 0x0545,
	0x3086, 0x8026,
	0x3086, 0xA627,
	0x3086, 0xF817,
	0x3086, 0x0227,
	0x3086, 0xFA5C,
	0x3086, 0x0B5F,
	0x3086, 0x5307,
	0x3086, 0x5302,
	0x3086, 0x4D28,
	0x3086, 0x6C4C,
	0x3086, 0x0928,
	0x3086, 0x2C28,
	0x3086, 0x294E,
	0x3086, 0x1718,
	0x3086, 0x26A2,
	0x3086, 0x5C03,
	0x3086, 0x1744,
	0x3086, 0x2809,
	0x3086, 0x27F2,
	0x3086, 0x1708,
	0x3086, 0x2809,
	0x3086, 0x1628,
	0x3086, 0x084D,
	0x3086, 0x1A26,
	0x3086, 0x8327,
	0x3086, 0xFA45,
	0x3086, 0xA017,
	0x3086, 0x0727,
	0x3086, 0xFB17,
	0x3086, 0x2945,
	0x3086, 0x8017,
	0x3086, 0x0827,
	0x3086, 0xFA17,
	0x3086, 0x285D,
	0x3086, 0x5300,
	0x3086, 0x17E8,
	0x3086, 0x5302,
	0x3086, 0x1710,
	0x3086, 0x2682,
	0x3086, 0x170E,
	0x3086, 0x484D,
	0x3086, 0x4E28,
	0x3086, 0x094C,
	0x3086, 0x0B17,
	0x3086, 0x5F28,
	0x3086, 0x0927,
	0x3086, 0xF217,
	0x3086, 0x0A28,
	0x3086, 0x0928,
	0x3086, 0x084D,
	0x3086, 0x1A27,
	0x3086, 0xFA26,
	0x3086, 0x025C,
	0x3086, 0x0045,
	0x3086, 0x4027,
	0x3086, 0x9817,
	0x3086, 0x2A4A,
	0x3086, 0x0A43,
	0x3086, 0x160B,
	0x3086, 0x4327,
	0x3086, 0x9C45,
	0x3086, 0x6017,
	0x3086, 0x0727,
	0x3086, 0x9D17,
	0x3086, 0x2545,
	0x3086, 0x4017,
	0x3086, 0x0827,
	0x3086, 0x985D,
	0x3086, 0x5307,
	0x3086, 0x2644,
	0x3086, 0x5C01,
	0x3086, 0x4B12,
	0x3086, 0x4452,
	0x3086, 0x5117,
	0x3086, 0x0260,
	0x3086, 0x184A,
	0x3086, 0x0343,
	0x3086, 0x1604,
	0x3086, 0x4316,
	0x3086, 0x5843,
	0x3086, 0x1659,
	0x3086, 0x4316,
	0x3086, 0x5A43,
	0x3086, 0x165B,
	0x3086, 0x4327,
	0x3086, 0x9C45,
	0x3086, 0x6017,
	0x3086, 0x0727,
	0x3086, 0x9D17,
	0x3086, 0x2545,
	0x3086, 0x4017,
	0x3086, 0x1027,
	0x3086, 0x9817,
	0x3086, 0x2022,
	0x3086, 0x4B12,
	0x3086, 0x442C,
	0x3086, 0x2C2C,
	0x3086, 0x2C00,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
/*	
	//ARRAY READOUT SETTINGS
	0x3004, 0,			// X_ADDR_START
	0x3008, 2303,		// X_ADDR_END
	0x3002, 124,    		// Y_ADDR_START
	0x3006, 1419,		// Y_ADDR_END

	//Sub-sampling
	0x30A2,1,			// X_ODD_INCREMENT
	0x30A6,1,			// Y_ODD_INCREMENT
	0x3040, 0,	//no bin

	//Frame-Timing
	0x300C, 1260,		// LINE_LENGTH_PCK
	0x300A, 1308,//1270,		// FRAME_LENGTH_LINES
	0x3014, 0,		// FINE_INTEGRATION_TIME
	0x3012, 1000,		// Coarse_Integration_Time
	0x3042, 0,			// EXTRA_DELAY
	0x30BA, 0x2C,
	0x301A,0x005C,			// Enable Streaming
*/	
};

#elif (SENSOR_IF == SENSOR_IF_MIPI_2_LANE)
//MIPI 2 Lane
MMP_USHORT SNR_MT9T002_Reg_Init_Customer[] = {
	0x31AE, 0x202,
	0x301A,0x0058, //disable streaming
	0xFFFF, 10, //delay 5us
	0x31AE, 0x202, //Output 2-lane MIPI
	//Configure for Serial Interface
	0x301A,0x0058, //Drive Pins,Parallel Enable,SMIA Serializer Disable
	0x3064, 0x1802, 	//Disable Embedded Data
	//Optimized Gain Configuration
	0x3EE0, 0x1500, 	// DAC_LD_20_21
	0x3EEA,0x001D,
	0x31E0,0x1E01,
	0x3F06,0x046A,
	0x3ED2,0x0186,	// upadate 9/30
	0x3ED4,0x8F2C,	// upadate 9/30
	0x3ED6,0x2244,	// upadate 9/30
	0x3ED8,0x6442,	// upadate 9/30
	0x30BA, 0x002C, //Dither enable
	0x3046, 0x4038,		// Enable Flash Pin
	0x3048, 0x8480,		// Flash Pulse Length
	 0x3ED0, 0x0016, 	// DAC_LD_4_5
	 0x3ED0, 0x0036, 	// DAC_LD_4_5
	 0x3ED0, 0x0076, 	// DAC_LD_4_5
	 0x3ED0, 0x00F6, 	// DAC_LD_4_5
	 0x3ECE, 0x1003, 	// DAC_LD_2_3
	 0x3ECE, 0x100F, 	// DAC_LD_2_3
	 0x3ECE, 0x103F, 	// DAC_LD_2_3
	 0x3ECE, 0x10FF, 	// DAC_LD_2_3
	 0x3ED0, 0x00F6, 	// DAC_LD_4_5
	 0x3ED0, 0x04F6, 	// DAC_LD_4_5
	 0x3ED0, 0x24F6, 	// DAC_LD_4_5
	 0x3ED0, 0xE4F6, 	// DAC_LD_4_5
	 0x3EE6, 0xA480, 	// DAC_LD_26_27
	 0x3EE6, 0xA080, 	// DAC_LD_26_27
	 0x3EE6, 0x8080, 	// DAC_LD_26_27
	 0x3EE6, 0x0080, 	// DAC_LD_26_27
	0x3EE6, 0x0080, 	// DAC_LD_26_27
	0x3EE8, 0x2024, 	// DAC_LD_28_29
	0x30FE, 128, //Noise Pedestal of 128

	//Assuming Input Clock of 24MHz.  Output Clock will be 70Mpixel/s
	 0x302A, 0x0005, 	// VT_PIX_CLK_DIV
	 0x302C, 0x0002, 	// VT_SYS_CLK_DIV
	 0x302E, 0x0004, 	// PRE_PLL_CLK_DIV
	 0x3030, 82, 	// PLL_MULTIPLIER
	 0x3036, 0x000A, 	// OP_PIX_CLK_DIV
	 0x3038, 0x0001, 	// OP_SYS_CLK_DIV
	 0x31AC, 0x0A0A, 	// DATA_FORMAT_BITS
	//MIPI TIMING
	0x31B0, 40,                          // FRAME PREAMBLE
	0x31B2, 14,                          // LINE PREAMBLE
	0x31B4, 0x2743,                      // MIPI TIMING 0
	0x31B6, 0x114E,                      // MIPI TIMING 1
	0x31B8, 0x2049,                      // MIPI TIMING 2
	0x31BA, 0x0186,                      // MIPI TIMING 3
	0x31BC, 0x8005,                      // MIPI TIMING 4
	0x31BE, 0x2003,                      // MIPI CONFIG STATUS
	//0x31B0, 41,
	//Sequencer
	0x3088, 0x8000,
	0x3086, 0x4540,
	0x3086, 0x6134,
	0x3086, 0x4A31,
	0x3086, 0x4342,
	0x3086, 0x4560,
	0x3086, 0x2714,
	0x3086, 0x3DFF,
	0x3086, 0x3DFF,
	0x3086, 0x3DEA,
	0x3086, 0x2704,
	0x3086, 0x3D10,
	0x3086, 0x2705,
	0x3086, 0x3D10,
	0x3086, 0x2715,
	0x3086, 0x3527,
	0x3086, 0x053D,
	0x3086, 0x1045,
	0x3086, 0x4027,
	0x3086, 0x0427,
	0x3086, 0x143D,
	0x3086, 0xFF3D,
	0x3086, 0xFF3D,
	0x3086, 0xEA62,
	0x3086, 0x2728,
	0x3086, 0x3627,
	0x3086, 0x083D,
	0x3086, 0x6444,
	0x3086, 0x2C2C,
	0x3086, 0x2C2C,
	0x3086, 0x4B01,
	0x3086, 0x432D,
	0x3086, 0x4643,
	0x3086, 0x1647,
	0x3086, 0x435F,
	0x3086, 0x4F50,
	0x3086, 0x2604,
	0x3086, 0x2684,
	0x3086, 0x2027,
	0x3086, 0xFC53,
	0x3086, 0x0D5C,
	0x3086, 0x0D60,
	0x3086, 0x5754,
	0x3086, 0x1709,
	0x3086, 0x5556,
	0x3086, 0x4917,
	0x3086, 0x145C,
	0x3086, 0x0945,
	0x3086, 0x0017,
	0x3086, 0x0545,
	0x3086, 0x8026,
	0x3086, 0xA627,
	0x3086, 0xF817,
	0x3086, 0x0227,
	0x3086, 0xFA5C,
	0x3086, 0x0B5F,
	0x3086, 0x5307,
	0x3086, 0x5302,
	0x3086, 0x4D28,
	0x3086, 0x6C4C,
	0x3086, 0x0928,
	0x3086, 0x2C28,
	0x3086, 0x294E,
	0x3086, 0x1718,
	0x3086, 0x26A2,
	0x3086, 0x5C03,
	0x3086, 0x1744,
	0x3086, 0x2809,
	0x3086, 0x27F2,
	0x3086, 0x1708,
	0x3086, 0x2809,
	0x3086, 0x1628,
	0x3086, 0x084D,
	0x3086, 0x1A26,
	0x3086, 0x8327,
	0x3086, 0xFA45,
	0x3086, 0xA017,
	0x3086, 0x0727,
	0x3086, 0xFB17,
	0x3086, 0x2945,
	0x3086, 0x8017,
	0x3086, 0x0827,
	0x3086, 0xFA17,
	0x3086, 0x285D,
	0x3086, 0x5300,
	0x3086, 0x17E8,
	0x3086, 0x5302,
	0x3086, 0x1710,
	0x3086, 0x2682,
	0x3086, 0x170E,
	0x3086, 0x484D,
	0x3086, 0x4E28,
	0x3086, 0x094C,
	0x3086, 0x0B17,
	0x3086, 0x5F28,
	0x3086, 0x0927,
	0x3086, 0xF217,
	0x3086, 0x0A28,
	0x3086, 0x0928,
	0x3086, 0x084D,
	0x3086, 0x1A27,
	0x3086, 0xFA26,
	0x3086, 0x025C,
	0x3086, 0x0045,
	0x3086, 0x4027,
	0x3086, 0x9817,
	0x3086, 0x2A4A,
	0x3086, 0x0A43,
	0x3086, 0x160B,
	0x3086, 0x4327,
	0x3086, 0x9C45,
	0x3086, 0x6017,
	0x3086, 0x0727,
	0x3086, 0x9D17,
	0x3086, 0x2545,
	0x3086, 0x4017,
	0x3086, 0x0827,
	0x3086, 0x985D,
	0x3086, 0x5307,
	0x3086, 0x2644,
	0x3086, 0x5C01,
	0x3086, 0x4B12,
	0x3086, 0x4452,
	0x3086, 0x5117,
	0x3086, 0x0260,
	0x3086, 0x184A,
	0x3086, 0x0343,
	0x3086, 0x1604,
	0x3086, 0x4316,
	0x3086, 0x5843,
	0x3086, 0x1659,
	0x3086, 0x4316,
	0x3086, 0x5A43,
	0x3086, 0x165B,
	0x3086, 0x4327,
	0x3086, 0x9C45,
	0x3086, 0x6017,
	0x3086, 0x0727,
	0x3086, 0x9D17,
	0x3086, 0x2545,
	0x3086, 0x4017,
	0x3086, 0x1027,
	0x3086, 0x9817,
	0x3086, 0x2022,
	0x3086, 0x4B12,
	0x3086, 0x442C,
	0x3086, 0x2C2C,
	0x3086, 0x2C00,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
/*	
	//ARRAY READOUT SETTINGS
	0x3004, 0,			// X_ADDR_START
	0x3008, 2303,		// X_ADDR_END
	0x3002, 124,    		// Y_ADDR_START
	0x3006, 1419,		// Y_ADDR_END

	//Sub-sampling
	0x30A2,1,			// X_ODD_INCREMENT
	0x30A6,1,			// Y_ODD_INCREMENT
	0x3040, 0,	//no bin

	//Frame-Timing
	0x300C, 1260,		// LINE_LENGTH_PCK
	0x300A, 1308,//1270,		// FRAME_LENGTH_LINES
	0x3014, 0,			// FINE_INTEGRATION_TIME
	0x3012, 1000,		// Coarse_Integration_Time
	0x3042, 0,			// EXTRA_DELAY
	0x30BA, 0x2C,
	0x301A,0x005C,			// Enable Streaming
*/
};

#elif (SENSOR_IF == SENSOR_IF_MIPI_4_LANE)
//MIPI 2 Lane
MMP_USHORT SNR_MT9T002_Reg_Init_Customer[] = {
	0x31AE, 0x204,		// 4-lane MIPI Output
	0x301A,0x0058, //disable streaming
	0xFFFF, 10, //delay 5us
	0x31AE, 0x204, //Output 4-lane MIPI
	//Configure for Serial Interface
	0x301A,0x0058, //Drive Pins,Parallel Enable,SMIA Serializer Disable
	0x3064, 0x1802, 	//Disable Embedded Data
	//Optimized Gain Configuration
	0x3EE0, 0x1500, 	// DAC_LD_20_21
	0x3EEA,0x001D,
	0x31E0,0x1E01,
	0x3F06,0x046A,
	0x3ED2,0x0186,	// upadate 9/30
	0x3ED4,0x8F2C,	// upadate 9/30
	0x3ED6,0x2244,	// upadate 9/30
	0x3ED8,0x6442,	// upadate 9/30
	0x30BA, 0x002C, //Dither enable
	0x3046, 0x4038,		// Enable Flash Pin
	0x3048, 0x8480,		// Flash Pulse Length
	 0x3ED0, 0x0016, 	// DAC_LD_4_5
	 0x3ED0, 0x0036, 	// DAC_LD_4_5
	 0x3ED0, 0x0076, 	// DAC_LD_4_5
	 0x3ED0, 0x00F6, 	// DAC_LD_4_5
	 0x3ECE, 0x1003, 	// DAC_LD_2_3
	 0x3ECE, 0x100F, 	// DAC_LD_2_3
	 0x3ECE, 0x103F, 	// DAC_LD_2_3
	 0x3ECE, 0x10FF, 	// DAC_LD_2_3
	 0x3ED0, 0x00F6, 	// DAC_LD_4_5
	 0x3ED0, 0x04F6, 	// DAC_LD_4_5
	 0x3ED0, 0x24F6, 	// DAC_LD_4_5
	 0x3ED0, 0xE4F6, 	// DAC_LD_4_5
	 0x3EE6, 0xA480, 	// DAC_LD_26_27
	 0x3EE6, 0xA080, 	// DAC_LD_26_27
	 0x3EE6, 0x8080, 	// DAC_LD_26_27
	 0x3EE6, 0x0080, 	// DAC_LD_26_27
	0x3EE6, 0x0080, 	// DAC_LD_26_27
	0x3EE8, 0x2024, 	// DAC_LD_28_29
	0x30FE, 128, //Noise Pedestal of 128

	//Assuming Input Clock of 24MHz.  Output Clock will be 70Mpixel/s
	 0x302A, 0x0005, 	// VT_PIX_CLK_DIV
	 0x302C, 0x0001, 	// VT_SYS_CLK_DIV **MIPI4
	 0x302E, 0x0004, 	// PRE_PLL_CLK_DIV
	 0x3030, 64,//80, 	// PLL_MULTIPLIER
	 0x3036, 0x000A, 	// OP_PIX_CLK_DIV
	 0x3038, 0x0001, 	// OP_SYS_CLK_DIV
	 0x31AC, 0x0A0A, 	// DATA_FORMAT_BITS
	//MIPI TIMING
	0x31B0, 40,                          // FRAME PREAMBLE
	0x31B2, 14,                          // LINE PREAMBLE
	0x31B4, 0x2743,                      // MIPI TIMING 0
	0x31B6, 0x114E,                      // MIPI TIMING 1
	0x31B8, 0x2049,                      // MIPI TIMING 2
	0x31BA, 0x0186,                      // MIPI TIMING 3
	0x31BC, 0x8005,                      // MIPI TIMING 4
	0x31BE, 0x2003,                      // MIPI CONFIG STATUS
	//0x31B0, 41,
	//Sequencer
	0x3088, 0x8000,
	0x3086, 0x4540,
	0x3086, 0x6134,
	0x3086, 0x4A31,
	0x3086, 0x4342,
	0x3086, 0x4560,
	0x3086, 0x2714,
	0x3086, 0x3DFF,
	0x3086, 0x3DFF,
	0x3086, 0x3DEA,
	0x3086, 0x2704,
	0x3086, 0x3D10,
	0x3086, 0x2705,
	0x3086, 0x3D10,
	0x3086, 0x2715,
	0x3086, 0x3527,
	0x3086, 0x053D,
	0x3086, 0x1045,
	0x3086, 0x4027,
	0x3086, 0x0427,
	0x3086, 0x143D,
	0x3086, 0xFF3D,
	0x3086, 0xFF3D,
	0x3086, 0xEA62,
	0x3086, 0x2728,
	0x3086, 0x3627,
	0x3086, 0x083D,
	0x3086, 0x6444,
	0x3086, 0x2C2C,
	0x3086, 0x2C2C,
	0x3086, 0x4B01,
	0x3086, 0x432D,
	0x3086, 0x4643,
	0x3086, 0x1647,
	0x3086, 0x435F,
	0x3086, 0x4F50,
	0x3086, 0x2604,
	0x3086, 0x2684,
	0x3086, 0x2027,
	0x3086, 0xFC53,
	0x3086, 0x0D5C,
	0x3086, 0x0D60,
	0x3086, 0x5754,
	0x3086, 0x1709,
	0x3086, 0x5556,
	0x3086, 0x4917,
	0x3086, 0x145C,
	0x3086, 0x0945,
	0x3086, 0x0017,
	0x3086, 0x0545,
	0x3086, 0x8026,
	0x3086, 0xA627,
	0x3086, 0xF817,
	0x3086, 0x0227,
	0x3086, 0xFA5C,
	0x3086, 0x0B5F,
	0x3086, 0x5307,
	0x3086, 0x5302,
	0x3086, 0x4D28,
	0x3086, 0x6C4C,
	0x3086, 0x0928,
	0x3086, 0x2C28,
	0x3086, 0x294E,
	0x3086, 0x1718,
	0x3086, 0x26A2,
	0x3086, 0x5C03,
	0x3086, 0x1744,
	0x3086, 0x2809,
	0x3086, 0x27F2,
	0x3086, 0x1708,
	0x3086, 0x2809,
	0x3086, 0x1628,
	0x3086, 0x084D,
	0x3086, 0x1A26,
	0x3086, 0x8327,
	0x3086, 0xFA45,
	0x3086, 0xA017,
	0x3086, 0x0727,
	0x3086, 0xFB17,
	0x3086, 0x2945,
	0x3086, 0x8017,
	0x3086, 0x0827,
	0x3086, 0xFA17,
	0x3086, 0x285D,
	0x3086, 0x5300,
	0x3086, 0x17E8,
	0x3086, 0x5302,
	0x3086, 0x1710,
	0x3086, 0x2682,
	0x3086, 0x170E,
	0x3086, 0x484D,
	0x3086, 0x4E28,
	0x3086, 0x094C,
	0x3086, 0x0B17,
	0x3086, 0x5F28,
	0x3086, 0x0927,
	0x3086, 0xF217,
	0x3086, 0x0A28,
	0x3086, 0x0928,
	0x3086, 0x084D,
	0x3086, 0x1A27,
	0x3086, 0xFA26,
	0x3086, 0x025C,
	0x3086, 0x0045,
	0x3086, 0x4027,
	0x3086, 0x9817,
	0x3086, 0x2A4A,
	0x3086, 0x0A43,
	0x3086, 0x160B,
	0x3086, 0x4327,
	0x3086, 0x9C45,
	0x3086, 0x6017,
	0x3086, 0x0727,
	0x3086, 0x9D17,
	0x3086, 0x2545,
	0x3086, 0x4017,
	0x3086, 0x0827,
	0x3086, 0x985D,
	0x3086, 0x5307,
	0x3086, 0x2644,
	0x3086, 0x5C01,
	0x3086, 0x4B12,
	0x3086, 0x4452,
	0x3086, 0x5117,
	0x3086, 0x0260,
	0x3086, 0x184A,
	0x3086, 0x0343,
	0x3086, 0x1604,
	0x3086, 0x4316,
	0x3086, 0x5843,
	0x3086, 0x1659,
	0x3086, 0x4316,
	0x3086, 0x5A43,
	0x3086, 0x165B,
	0x3086, 0x4327,
	0x3086, 0x9C45,
	0x3086, 0x6017,
	0x3086, 0x0727,
	0x3086, 0x9D17,
	0x3086, 0x2545,
	0x3086, 0x4017,
	0x3086, 0x1027,
	0x3086, 0x9817,
	0x3086, 0x2022,
	0x3086, 0x4B12,
	0x3086, 0x442C,
	0x3086, 0x2C2C,
	0x3086, 0x2C00,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
	0x3086, 0x0000,
/*	
	//ARRAY READOUT SETTINGS
	0x3004, 0,			// X_ADDR_START
	0x3008, 2303,		// X_ADDR_END
	0x3002, 124,    		// Y_ADDR_START
	0x3006, 1419,		// Y_ADDR_END

	//Sub-sampling
	0x30A2,1,			// X_ODD_INCREMENT
	0x30A6,1,			// Y_ODD_INCREMENT
	0x3040, 0,	//no bin

	//Frame-Timing
	0x300C, 1260,		// LINE_LENGTH_PCK
	0x300A, 1308,//1270,		// FRAME_LENGTH_LINES
	0x3014, 0,			// FINE_INTEGRATION_TIME
	0x3012, 1000,		// Coarse_Integration_Time
	0x3042, 0,			// EXTRA_DELAY
	0x30BA, 0x2C,
	0x301A,0x005C,			// Enable Streaming
*/
};

#endif

void SNR_MT9T002_InitSensor_Customer(void) {
	// implement your initialize sensor routine here ==============================================
	ISP_UINT16 data ;

	ISP_UINT32 i;

	// initialize I2C ID and type
	/*
	VR_SNR_ConfigI2C(	VR_TableN_GetValueByIndex(&gIspTableHeader.Sensor_Misc, 0),
						VR_TableN_GetValueByIndex(&gIspTableHeader.Sensor_Misc, 1));
	*/
	RTNA_WAIT_MS(10);
	MMPF_Sensor_ConfigI2C( 0x10, ISP_I2C_TYPE_2A2D);

	// initialize VIF OPRs
	//ISP_HDM_IF_InitVIF(ISP_HDM_VIF_IF_PARALLEL, 22);
#if (SENSOR_IF == SENSOR_IF_MIPI_1_LANE)	
	ISP_HDM_IF_InitVIF(ISP_HDM_VIF_IF_MIPI_SINGLE_0, 22);
#elif (SENSOR_IF == SENSOR_IF_MIPI_2_LANE)		
	ISP_HDM_IF_InitVIF(ISP_HDM_VIF_IF_MIPI_DUAL_01, 22);
#elif (SENSOR_IF == SENSOR_IF_MIPI_4_LANE)		
	ISP_HDM_IF_InitVIF(ISP_HDM_VIF_IF_MIPI_QUAD, 22);
#endif	
	RTNA_WAIT_MS(10);
	ISP_HDM_IF_EnableSensor(ISP_HDM_SNR_ENABLE_HIGH);

	// set register...........
	for (i = 0; i < VR_ARRSIZE(SNR_MT9T002_Reg_Init_Customer)/2; i++) {
	    if(SNR_MT9T002_Reg_Init_Customer[i*2] == 0xFFFF)
	        MMPF_OS_Sleep_MS(SNR_MT9T002_Reg_Init_Customer[i*2+1]);
	    else
			MMPF_Sensor_WriteI2C(SNR_MT9T002_Reg_Init_Customer[i*2], SNR_MT9T002_Reg_Init_Customer[i*2+1]);

#if 0
		data = MMPF_Sensor_ReadI2C(SNR_MT9T002_Reg_Init_Customer[i*2]) ;
		RTNA_DBG_Str3("Reg :");
		RTNA_DBG_Short3(SNR_MT9T002_Reg_Init_Customer[i*2]);
		RTNA_DBG_Str3(",");
		RTNA_DBG_Short3(data);
		RTNA_DBG_Str3("\r\n");
#endif
	}

	//ISP_IF_AE_SetBaseShutter(346, 288, 346, 288);
	ISP_IF_AE_SetBaseShutter( 391, 326, 391, 326);

	// Set preview resolution as default
	ISP_IF_SNR_SetResolution(ISP_SENSOR_RESOL_1920x1080);
}

void SNR_MT9T002_SetSensorGain_Customer(ISP_UINT32 gain)
{

	ISP_UINT16 sensor_again;
	ISP_UINT16 sensor_dgain;
	
	// Sensor Gain Mapping
	if 		(gain < 0x80)  {sensor_dgain = gain << 1;	sensor_again = 0x0;}	// 1X ~ 2X

	else if (gain < 0x100)  {sensor_dgain = gain;	sensor_again = 0x10;}		// 2X ~ 4X

	else if (gain < 0x200) {sensor_dgain = gain >> 1;	sensor_again = 0x20;}	// 4X ~ 8X

	else 				{sensor_dgain = gain >> 2;	sensor_again = 0x30;}		// 8X ~16X

	MMPF_Sensor_WriteI2C(0x305E, sensor_dgain);
	MMPF_Sensor_WriteI2C(0x3060, sensor_again);

}

void SNR_MT9T002_SetSensorShutter_Customer(ISP_UINT32 shutter, ISP_UINT32 vsync)
{
	ISP_UINT32 new_vsync = VR_MIN(VR_MAX(shutter + 3, vsync), 0xFFFF);
	ISP_UINT32 new_shutter = VR_MIN(VR_MAX(shutter, 1), new_vsync - 3);

	MMPF_Sensor_WriteI2C(0x300A, new_vsync);
	MMPF_Sensor_WriteI2C(0x3012, new_shutter);
}

void SNR_MT9T002_SetSensorAddMode_Customer(ISP_UINT8 enable)
{
/*	if (ISP_HDM_IF_IsFrameTypePreview()) {
		ISP_UINT8 regval = (enable) ? MMPF_Sensor_ReadI2C(0x3016) | 0x40 : MMPF_Sensor_ReadI2C(0x3016) & ~0x40;

		MMPF_Sensor_WriteI2C(0x0104, 0x01); // grouped_parameter_hold
		MMPF_Sensor_WriteI2C(0x3016, regval);
		MMPF_Sensor_WriteI2C(0x0104, 0x00); // grouped_parameter_hold
	}
*/
}

#if (SENSOR_IF == SENSOR_IF_MIPI_4_LANE)		

ISP_UINT16 SNR_MT9T002_Reg_2304x1296[] = {

	0x3030, 40, 	// PLL_MULTIPLIER  @ 240Mbps/lane
	//0x3030, 82, 	// PLL_MULTIPLIER  @ 490Mbps/lane

    //ARRAY READOUT SETTINGS
    0x3004, 0,			// X_ADDR_START
	0x3008, 2311,//2303,		// X_ADDR_END
	0x3002, 0,//124,    		// Y_ADDR_START
	0x3006, 1299,//1303,//1419,		// Y_ADDR_END

    //Sub-sampling
    0x30A2, 1,			// X_ODD_INCREMENT
    0x30A6, 1,			// Y_ODD_INCREMENT
	0x3040, 0x0000,	// [15]: flip, [14]: mirror, [12]: Row binning, [13]: column binning 

    //Frame-Timing
    0x300C, 1260,		// LINE_LENGTH_PCK
    0x300A, 1312,		// FRAME_LENGTH_LINES
    0x3014, 0,			// FINE_INTEGRATION_TIME
    0x3012, 1000,		// Coarse_Integration_Time
    0x3042, 0,			// EXTRA_DELAY
    0x30BA, 0x2C,	    // Digital_Ctrl_Adc_High_Speed
  
    0x301A, 0x000C, //Grouped Parameter Hold = 0x0
};

ISP_UINT16 SNR_MT9T002_Reg_1920x1080[] = {

	0x3030, 40, 	// PLL_MULTIPLIER  @ 240Mbps/lane

    //ARRAY READOUT SETTINGS
	0x3004, 192,			// X_ADDR_START
	0x3008, 2127,		// X_ADDR_END
	0x3002, 232,    		// Y_ADDR_START
	0x3006, 1319,		// Y_ADDR_END

    //Sub-sampling
    0x30A2, 1,			// X_ODD_INCREMENT
    0x30A6, 1,			// Y_ODD_INCREMENT
    0x3040, 0, 	// Row Bin, [12]: Row binning, [13]: column binning

    //Frame-Timing
    0x300C, 1260,//1056,		// LINE_LENGTH_PCK
    0x300A, 1270,//1092,		// FRAME_LENGTH_LINES
    0x3014, 136,			// FINE_INTEGRATION_TIME
    0x3012, 1000,		// Coarse_Integration_Time
    0x3042, 0,			// EXTRA_DELAY
    0x30BA, 0x2C,	// Digital_Ctrl_Adc_High_Speed
  
 	0x301A, 0x000C, //Grouped Parameter Hold = 0x0
};

ISP_UINT16 SNR_MT9T002_Reg_1152x648[] = {

	0x3030, 42, 	// PLL_MULTIPLIER  @ 430Mbps/lane
	//0x3030, 82, 	// PLL_MULTIPLIER  @ 490Mbps/lane

    //ARRAY READOUT SETTINGS
	0x3004, 0,			// X_ADDR_START
	0x3008, 2311,//2303,		// X_ADDR_END
//	0x3002, 120,//124,    		// Y_ADDR_START
//	0x3006, 1423,//1419,		// Y_ADDR_END
	0x3002, 0,//124,    		// Y_ADDR_START
	0x3006, 1303,//1419,		// Y_ADDR_END

    //Sub-sampling
    0x30A2, 3,			// X_ODD_INCREMENT
    0x30A6, 3,			// Y_ODD_INCREMENT
    0x3040, 0x3000, 	// Row-colum Bin, [12]: Row binning, [13]: column binning

    //Frame-Timing
    0x300C, 1250,		// LINE_LENGTH_PCK
    0x300A, 660+8,		// FRAME_LENGTH_LINES
    0x3014, 0,			// FINE_INTEGRATION_TIME
    0x3012, 550,		// Coarse_Integration_Time
    0x3042, 0,			// EXTRA_DELAY
    0x30BA, 0x2C,	// Digital_Ctrl_Adc_High_Speed
  
    0x301A, 0x000C, //Grouped Parameter Hold = 0x0
};

ISP_UINT16 SNR_MT9T002_Reg_2304x648[] = {

	0x3030, 42, 	// PLL_MULTIPLIER  @ 430Mbps/lane
	//0x3030, 82, 	// PLL_MULTIPLIER  @ 490Mbps/lane

    //ARRAY READOUT SETTINGS
	0x3004, 0,			// X_ADDR_START
	0x3008, 2311,//2303,		// X_ADDR_END
//	0x3002, 120,//124,    		// Y_ADDR_START
//	0x3006, 1423,//1419,		// Y_ADDR_END
	0x3002, 0,//124,    		// Y_ADDR_START
	0x3006, 1303,//1419,		// Y_ADDR_END

    //Sub-sampling
    0x30A2, 1,			// X_ODD_INCREMENT
    0x30A6, 3,			// Y_ODD_INCREMENT
    0x3040, 0x1000, 	// Row-colum Bin, [12]: Row binning, [13]: column binning

    //Frame-Timing
    0x300C, 1260,		// LINE_LENGTH_PCK
    0x300A, 660+8,		// FRAME_LENGTH_LINES
    0x3014, 0,			// FINE_INTEGRATION_TIME
    0x3012, 550,		// Coarse_Integration_Time
    0x3042, 0,			// EXTRA_DELAY
    0x30BA, 0x2C,	// Digital_Ctrl_Adc_High_Speed
  
    0x301A, 0x000C, //Grouped Parameter Hold = 0x0
};


#else //MIPI 2-lane

ISP_UINT16 SNR_MT9T002_Reg_2304x1296[] = {

	0x3030, 82, 	// PLL_MULTIPLIER  @ 490Mbps/lane

	//ARRAY READOUT SETTINGS
	0x3004, 0,			// X_ADDR_START
	0x3008, 2311,//2303,		// X_ADDR_END
	0x3002, 122,//0,//124,    		// Y_ADDR_START
	0x3006, 1421,//1299,//1303,//1419,		// Y_ADDR_END

	//Sub-sampling
	0x30A2, 1,			// X_ODD_INCREMENT
	0x30A6, 1,			// Y_ODD_INCREMENT
	0x3040, 0x0000,	// [15]: flip, [14]: mirror, [12]: Row binning, [13]: column binning

	0x300C, 1250,//1248, // LINE_LENGTH_PCK
	0x300A, 1312,//1092,		// FRAME_LENGTH_LINES
	0x3014, 0,		// FINE_INTEGRATION_TIME
	0x3012, 1000,		// Coarse_Integration_Time
	0x3042, 0,			// EXTRA_DELAY
	0x30BA, 0x2C,

	0x301A, 0x000C, //Grouped Parameter Hold = 0x0

};

ISP_UINT16 SNR_MT9T002_Reg_1920x1080[] = {

	0x3030, 82, 	// PLL_MULTIPLIER  @ 490Mbps/lane

	//ARRAY READOUT SETTINGS
	0x3004, 192,			// X_ADDR_START
	0x3008, 2127,		// X_ADDR_END
	0x3002, 232,    		// Y_ADDR_START
	0x3006, 1319,		// Y_ADDR_END

	//Sub-sampling
	0x30A2, 1,			// X_ODD_INCREMENT
	0x30A6, 1,			// Y_ODD_INCREMENT
	0x3040, 0x0000,	// [15]: flip, [14]: mirror, [12]: Row binning, [13]: column binning

	0x300C, 1260,//1190,		// LINE_LENGTH_PCK
	0x300A, 1270,//1092,		// FRAME_LENGTH_LINES
	0x3014, 0,		// FINE_INTEGRATION_TIME
	0x3012, 1000,		// Coarse_Integration_Time
	0x3042, 0,			// EXTRA_DELAY
	0x30BA, 0x2C,

	0x301A, 0x000C, //Grouped Parameter Hold = 0x0

};

ISP_UINT16 SNR_MT9T002_Reg_1152x648[] = {

	0x3030, 82, 	// PLL_MULTIPLIER @ 490Mbps/lane

    //ARRAY READOUT SETTINGS
	0x3004, 0,			// X_ADDR_START
	0x3008, 2311,//2303,		// X_ADDR_END
	0x3002, 120,//124,    		// Y_ADDR_START
	0x3006, 1423,//1419,		// Y_ADDR_END

    //Sub-sampling
    0x30A2, 3,			// X_ODD_INCREMENT
    0x30A6, 3,			// Y_ODD_INCREMENT
    0x3040, 0x3000, 	// Row-colum Bin, [12]: Row binning, [13]: column binning

    //Frame-Timing
    0x300C, 1260,//920,		// LINE_LENGTH_PCK
    0x300A, 660,		// FRAME_LENGTH_LINES
    0x3014, 0,			// FINE_INTEGRATION_TIME
    0x3012, 552,		// Coarse_Integration_Time
    0x3042, 0,			// EXTRA_DELAY
    0x30BA, 0x2C,	// Digital_Ctrl_Adc_High_Speed
  
    0x301A, 0x000C, //Grouped Parameter Hold = 0x0
};

#endif

void SNR_MT9T002_SetSensorResolution_Customer(ISP_SENSOR_RESOL res)
{
	// implement your change sensor resolution routine here =======================================

	ISP_UINT32 i;

	switch (res) {
	case ISP_SENSOR_RESOL_1920x1080:
	case ISP_SENSOR_RESOL_1280x960:
	case ISP_SENSOR_RESOL_1280x720:

#if CROP_1080P_FROM_2304_1296
		// set register...........
		for (i = 0; i < VR_ARRSIZE(SNR_MT9T002_Reg_1920x1080)/2; i++) {
			MMPF_Sensor_WriteI2C(SNR_MT9T002_Reg_1920x1080[i*2], SNR_MT9T002_Reg_1920x1080[i*2+1]);
	    }
#else
		// set register...........
		for (i = 0; i < VR_ARRSIZE(SNR_MT9T002_Reg_2304x1296)/2; i++) {
			MMPF_Sensor_WriteI2C(SNR_MT9T002_Reg_2304x1296[i*2], SNR_MT9T002_Reg_2304x1296[i*2+1]);
	    }
#endif

		// set sensor vsync
#if CROP_1080P_FROM_2304_1296
		gIspIfSnrResolInfo.SensorVsync         = 1270;
#else
		gIspIfSnrResolInfo.SensorVsync         = 1312;
#endif		
		gIspIfSnrResolInfo.TargetFPS           = 30;

#if CROP_1080P_FROM_2304_1296
		// set vif grab range (for scaler calculation)
		gIspIfSnrResolInfo.VIFGrab_H_Start     = 1;
		gIspIfSnrResolInfo.VIFGrab_H_Length    = 1936;
		gIspIfSnrResolInfo.VIFGrab_V_Start     = 1;
		gIspIfSnrResolInfo.VIFGrab_V_Length    = 1088;

		// set scaler grab range (for scaler calculation)
		gIspIfSnrResolInfo.ScalerGrab_H_Length = 1922;
		gIspIfSnrResolInfo.ScalerGrab_V_Length = 1082;
#else

	// set vif grab range (for scaler calculation)
		gIspIfSnrResolInfo.VIFGrab_H_Start     = 1;
		gIspIfSnrResolInfo.VIFGrab_H_Length    = 2304+8;
		gIspIfSnrResolInfo.VIFGrab_V_Start     = 1;
		gIspIfSnrResolInfo.VIFGrab_V_Length    = 1296+4;

	// set scaler grab range (for scaler calculation)
		gIspIfSnrResolInfo.ScalerGrab_H_Length = 2304;
		gIspIfSnrResolInfo.ScalerGrab_V_Length = 1296;

#endif

		// set scaler downsample rate (for scaler calculation)
		gIspIfSnrResolInfo.H_DownSample        = 1;
		gIspIfSnrResolInfo.V_DownSample        = 1;

		// set color id
		gIspIfSnrResolInfo.ColorID 			= 1;
		break;

	case ISP_SENSOR_RESOL_800x600:
	case ISP_SENSOR_RESOL_640x480:

#if ENABLE_ROW_BINNING_2304_648
		// set register...........
		for (i = 0; i < VR_ARRSIZE(SNR_MT9T002_Reg_2304x648)/2; i++) {
			MMPF_Sensor_WriteI2C(SNR_MT9T002_Reg_2304x648[i*2], SNR_MT9T002_Reg_2304x648[i*2+1]);
	    }
#else
		// set register...........
		for (i = 0; i < VR_ARRSIZE(SNR_MT9T002_Reg_1152x648)/2; i++) {
			MMPF_Sensor_WriteI2C(SNR_MT9T002_Reg_1152x648[i*2], SNR_MT9T002_Reg_1152x648[i*2+1]);
	    }
#endif

		// set sensor vsync
		gIspIfSnrResolInfo.SensorVsync         = 660+8;
		gIspIfSnrResolInfo.TargetFPS           = 30;

#if ENABLE_ROW_BINNING_2304_648
	// set vif grab range (for scaler calculation)
		gIspIfSnrResolInfo.VIFGrab_H_Start     = 1;
		gIspIfSnrResolInfo.VIFGrab_H_Length    = 2304 + 8;
		gIspIfSnrResolInfo.VIFGrab_V_Start     = 1;
		gIspIfSnrResolInfo.VIFGrab_V_Length    = 648 + 4;

	// set scaler grab range (for scaler calculation)
		gIspIfSnrResolInfo.ScalerGrab_H_Length = 2304;
		gIspIfSnrResolInfo.ScalerGrab_V_Length = 648;
#else
	// set vif grab range (for scaler calculation)
		gIspIfSnrResolInfo.VIFGrab_H_Start     = 1;
		gIspIfSnrResolInfo.VIFGrab_H_Length    = 1152 + 4;
		gIspIfSnrResolInfo.VIFGrab_V_Start     = 1;
		gIspIfSnrResolInfo.VIFGrab_V_Length    = 648 + 4;

	// set scaler grab range (for scaler calculation)
		gIspIfSnrResolInfo.ScalerGrab_H_Length = 1152;
		gIspIfSnrResolInfo.ScalerGrab_V_Length = 648;
#endif

		// set scaler downsample rate (for scaler calculation)
		gIspIfSnrResolInfo.H_DownSample        = 1;
		gIspIfSnrResolInfo.V_DownSample        = 1;

		// set color id
		gIspIfSnrResolInfo.ColorID 			= 1;
		break;
	}

	// end of your implementation =================================================================


	// Keep the latest settings (should be set before the following settings)
	gIspIfSnrResolInfo.CurrentResolution   = res;
}

void SNR_MT9T002_DoAWB_Customer(void)
{
	static ISP_UINT32 frame_cnt = 0;

	switch (frame_cnt++ % 6) {
	case 3:
	case 5:
		ISP_IF_AWB_Execute();
		ISP_IF_AWB_SetDGain();
		break;
	}
}

void SNR_MT9T002_DoAF_Customer(void)
{
	static ISP_UINT32 frame_cnt = 0;

	switch (frame_cnt++ % 1) {
	case 0:
		ISP_IF_AF_Execute();
		break;
	}
}


#if (SENSOR_ID_MT9T002== 0)
MMPF_SENSOR_FUNCTION  *SensorFunction_Module0 = &SensorFunction_MT9T002;
#endif

#if (SENSOR_ID_MT9T002== 1)
MMPF_SENSOR_FUNCTION  *SensorFunction_Module1 = &SensorFunction_MT9T002;
#endif

#endif  //BIND_SENSOR_MT9T002
#endif
